package com.yami.shop.api.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.app.dto.CarListDto;
import com.yami.shop.bean.app.dto.CarUserDto;
import com.yami.shop.bean.app.dto.CarUserManDto;
import com.yami.shop.bean.app.param.CarUserAuthParam;
import com.yami.shop.bean.app.param.CarUserReviewParam;
import com.yami.shop.bean.model.CarUser;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.api.util.SecurityUtils;
import com.yami.shop.service.CarUserService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * CarUserController
 *
 * @Author Administrator
 * @Date 2025/4/14 12:45
 */
@RestController
@RequestMapping("/p/carUser")
@RequiredArgsConstructor
public class CarUserController {
    private final CarUserService carUserService;
    @GetMapping("/userInfo")
    @Operation(summary = "查看用户信息" , description = "根据用户ID（userId）获取用户信息")
    public ServerResponseEntity<CarUserDto> userInfo() {
        Integer userId = SecurityUtils.getUser().getUserId();
        CarUser user = carUserService.getById(userId);
        CarUserDto userDto = BeanUtil.copyProperties(user, CarUserDto.class);
        return ServerResponseEntity.success(userDto);
    }

    @PostMapping("/submitAuth")
    @Operation(summary = "查看用户信息" , description = "根据用户ID（userId）获取用户信息")
    public ServerResponseEntity<Void> submitAuth(@Validated @RequestBody CarUserAuthParam param) {
        Integer userId = SecurityUtils.getUser().getUserId();
        param.setUserId(userId);
        carUserService.submitAuth(param);
        return ServerResponseEntity.success();
    }

    @GetMapping("/userList")
    @Operation(summary = "查看用户信息" , description = "根据用户ID（userId）获取用户信息")
    public ServerResponseEntity<IPage<CarUserManDto>> userList(PageParam<CarUserManDto> page) {
        Integer userId = SecurityUtils.getUser().getUserId();
        IPage<CarUserManDto> carUserManDtoIPage = carUserService.userList(page,userId);
        return ServerResponseEntity.success(carUserManDtoIPage);
    }

    @PostMapping("/review")
    @Operation(summary = "查看用户信息" , description = "根据用户ID（userId）获取用户信息")
    public ServerResponseEntity<Void> review(@Validated @RequestBody CarUserReviewParam param) {
        Integer manUserId = SecurityUtils.getUser().getUserId();
        carUserService.review(manUserId,param);
        return ServerResponseEntity.success();
    }
}
